#include "stdafx.h"
#include "DispatchImpl.h"

CDispatchImpl::CDispatchImpl()
	: m_RefCount(0)
{
}

CDispatchImpl::~CDispatchImpl()
{
}

STDMETHODIMP CDispatchImpl::QueryInterface( /* [in] */ REFIID riid, /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject )
{
	if (riid == IID_IUnknown)
	{
		*ppvObject = dynamic_cast<IUnknown*>(this);
		
		if (*ppvObject)
		{
			AddRef();
			return S_OK; 
		}
	}
	else if (riid == IID_IDispatch)
	{
		*ppvObject = dynamic_cast<IDispatch*>(this);
		
		if (*ppvObject)
		{
			AddRef();
			return S_OK; 
		}
	}
	
	return E_FAIL;
}

ULONG STDMETHODCALLTYPE CDispatchImpl::AddRef( void )
{
	m_RefCount++;
	return m_RefCount;
}

ULONG STDMETHODCALLTYPE CDispatchImpl::Release( void )
{
	m_RefCount--;
	ULONG lRet = m_RefCount;
	if (m_RefCount == 0)
		delete this;
	return lRet;
}

STDMETHODIMP CDispatchImpl::GetTypeInfoCount( UINT* pctinfo )
{
	*pctinfo = 1;
	return E_NOTIMPL;
}

STDMETHODIMP CDispatchImpl::GetTypeInfo( UINT itinfo, LCID lcid, ITypeInfo** pptinfo )
{
	return E_NOTIMPL;
}

STDMETHODIMP CDispatchImpl::GetIDsOfNames( REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid )
{
	return E_NOTIMPL;
}

STDMETHODIMP CDispatchImpl::Invoke( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr )
{
	return E_NOTIMPL;
}